package com.modifiertech.lineage.client.gui.ftbint;

import com.feed_the_beast.ftblib.lib.gui.Panel;
import com.feed_the_beast.ftblib.lib.gui.PanelScrollBar;
import com.feed_the_beast.ftblib.lib.gui.Theme;
import com.feed_the_beast.ftblib.lib.icon.Color4I;

public class PanelWarpper<T> extends Panel {
    private PanelWarpperScroll  innerPanelRel;
    private PanelScrollBar panelScrollBarV,panelScrollBarH;


    public PanelWarpper(Panel panel) {
        super(panel);
    }

    public void doInit(PanelWarpperScroll innerPanelRel){
        this.innerPanelRel=  innerPanelRel;
        init();
        this.innerPanelRel.setRelPanelScrollBarH(panelScrollBarH);
        this.innerPanelRel.setRelPanelScrollBarV(panelScrollBarV);
    }

    private void init() {
        //init v,h
        // init v
        this.setPanelScrollBarV(new PanelScrollBar(this, ((Panel)this.getInnerPanelRel())));
        this.getPanelScrollBarV().setCanAlwaysScroll(false);
        this.getPanelScrollBarV().setCanAlwaysScrollPlane(true);
        this.getPanelScrollBarV().setScrollStep(10);
        //init h
        this.setPanelScrollBarH(new PanelScrollBar(this,PanelScrollBar.Plane.HORIZONTAL,((Panel)this.getInnerPanelRel())));
        this.getPanelScrollBarH().setCanAlwaysScroll(false);
        this.getPanelScrollBarH().setCanAlwaysScrollPlane(true);
        this.getPanelScrollBarH().setScrollStep(10);
    }

//    @Override
//    public void tick() {
//        super.tick();
//        ((Panel)this.innerPanelRel).tick();
//    }

    @Override
    public void addWidgets() {
        add((Panel) getInnerPanelRel());
        add(getPanelScrollBarH());
        add(getPanelScrollBarV());
    }

    @Override
    public void alignWidgets() {
        ((Panel)this.getInnerPanelRel())
                .setPosAndSize(0,0,width-10,height-10);
        ((Panel)this.getInnerPanelRel()).alignWidgets();
        //v
        this.getPanelScrollBarV().setPosAndSize(width-8,0,8,height-9);
        this.getPanelScrollBarV().setMaxValue(((Panel)this.getInnerPanelRel()).getContentHeight());
        //h
        this.getPanelScrollBarH().setPosAndSize(0,height-10,width-9,8);
        this.getPanelScrollBarH().setMaxValue(((Panel)this.getInnerPanelRel()).getContentWidth());
    }

    @Override
    public void drawBackground(Theme theme, int x, int y, int w, int h) {
        Color4I.BLACK.withAlpha(30).withBorder(Color4I.GRAY,true).draw(x, y, w, h);
    }

    public PanelWarpperScroll getInnerPanelRel() {
        return innerPanelRel;
    }

    public void setInnerPanelRel(PanelWarpperScroll innerPanelRel) {
        this.innerPanelRel = innerPanelRel;
    }

    public PanelScrollBar getPanelScrollBarV() {
        return panelScrollBarV;
    }

    public void setPanelScrollBarV(PanelScrollBar panelScrollBarV) {
        this.panelScrollBarV = panelScrollBarV;
    }

    public PanelScrollBar getPanelScrollBarH() {
        return panelScrollBarH;
    }

    public void setPanelScrollBarH(PanelScrollBar panelScrollBarH) {
        this.panelScrollBarH = panelScrollBarH;
    }
}
